/**
 * @param {string} word1
 * @param {string} word2
 * @return {number}
 */

var minDistance = function (word1, word2) {
    let row = word1.length
    let col = word2.length
    let dp = new Array(row + 1).fill(0)
    for (let i = 0; i <= row; i++) {
        dp[i] = new Array(col + 1).fill(0)
    }
    for (let i = 0; i <= col; i++) {
        dp[0][i] = i
    }
    for (let i = 0; i <= row; i++) {
        dp[i][0] = i
    }
    for (let i = 1; i <= row; i++) {
        for (let j = 1; j <= col; j++) {
            if (word1[i - 1] == word2[j - 1]) {
                dp[i][j] = dp[i - 1][j - 1];
            } else {
                dp[i][j] = Math.min(Math.min(dp[i - 1][j - 1], dp[i][j - 1]), dp[i - 1][j]) + 1;
            }
        }
    }
    console.log(dp)
    return dp[row][col]
};
console.log(minDistance("horse", "ros"))